from django.db import models

from Apps.User.models import User
from Apps.common.custommodel import CustomModel
from Apps.util.snowFlake import get_guid


class Project(CustomModel):
    """
    公开项目:所有人可见该项目
    项目成员:该项目的成员可新增和编辑，执行，当前自己的项目(自己新建的接口和自己是责任人)
    项目管理员:对该项目有所有权，可编辑项目，可编辑项目下面的任务，编辑成员
    超级管理员:有所有权限，可删除和新建项目
    """
    project_icon = models.CharField(max_length=256, default="", verbose_name="项目图标")
    project_name = models.CharField(max_length=50, default="", verbose_name="项目名称")
    description = models.TextField(default="", null=True, verbose_name="项目描述")
    index = models.CharField(max_length=20, default=get_guid, verbose_name="排序", null=True)
    is_open = models.BooleanField(default=False, verbose_name="是否公开项目")
    is_delete = models.BooleanField(default=False, verbose_name="项目是否删除")
    project_managers = models.ForeignKey(to=User, null=True, db_constraint=False, related_name="project_managers",
                                         on_delete=models.SET_NULL, help_text="关联用户", verbose_name="关联用户", )

    project_members = models.ManyToManyField(to=User, blank=True, db_constraint=False, related_name="project_members",
                                             help_text="关联用户", verbose_name="关联用户", )

    class Meta:
        db_table = "project"
        verbose_name = db_table
        ordering = ('-index',)

    def __str__(self):
        return self.project_name
